from django.template import Library
from django.urls import reverse
from web import models

register=Library()

@register.inclusion_tag('inclusion/all_project_list.html')
def all_project_list(request):
    #获取
    my_project_list = models.Project.objects.filter(creator=request.tracer.user)
    join_project_list = models.ProjectUser.objects.filter(user=request.tracer.user)
    return {'my':my_project_list,'join':join_project_list}

@register.inclusion_tag('inclusion/menu_list.html')
def menu_list(request):
    mList=[
        {'url':reverse('web:dashboard',kwargs={'project_id':request.tracer.project.id}),'title':'概览'},
        {'url': reverse('web:issue', kwargs={'project_id': request.tracer.project.id}), 'title': '问题'},
        {'url': reverse('web:wiki', kwargs={'project_id': request.tracer.project.id}), 'title': 'wiki'},
        {'url': reverse('web:statistics', kwargs={'project_id': request.tracer.project.id}), 'title': '统计'},
        {'url': reverse('web:file', kwargs={'project_id': request.tracer.project.id}), 'title': '文件'},
        {'url': reverse('web:setting', kwargs={'project_id': request.tracer.project.id}), 'title': '设置'},
    ]
    for item in mList:
        if request.path.startswith(item['url']):
            item['class']='active'
    return {'menu':mList}